import React, { Component } from "react";

// NavLink它具有Link所有的功能，除此之外，它还可以做导航高亮
// 被选中的那一项就会自动添加active的类名
import { NavLink, Route, Switch } from "react-router-dom";

import "./09-style.css";

class Home extends Component {
  render() {
    return <div>这是home页面</div>;
  }
}
class About extends Component {
  render() {
    return <div>这是about页面</div>;
  }
}

class App extends Component {
  render() {
    return (
      <>
        <h2>react-router-v5-导航高亮</h2>
        <ul>
          <li>
            {/* 高亮是通过比对url和to属性 */}
            {/* 也是模糊匹配 */}
            {/* activeClassName可以改变默认的active类名 */}
            <NavLink to="/" exact activeClassName="select">
              首页
            </NavLink>
          </li>
          <li>
            <NavLink to="/about" activeClassName="select">
              关于页
            </NavLink>
          </li>
        </ul>

        <Switch>
          {/* <Redirect from="/" to="/home" exact></Redirect> */}
          <Route path="/" component={Home} exact></Route>
          <Route path="/about" component={About}></Route>
        </Switch>
      </>
    );
  }
}

export default App;
